#!/bin/sh /etc/rc.common

NAME=airplay
START=99

handle_airplay() {
	local config="$1"
	local custom="$2"
	local bname
	local initbuf
	local port
	local password
	local daemonize
        local pcm
        local ctl
        local volume
		
	config_get bname "$1" bname "wairplay"
	config_get initbuf "$1" initbuf "220"
	config_get port "$1" port "5002"
	config_get password "$1" password
	config_get_bool daemonize "$1" daemonize 1
        config_get pcm "$1" pcm "default"
        config_get ctl "$1" ctl "default"
        config_get volume "$1" volume "Speaker"
	
	shairport -a "$bname" -b $initbuf -p $port -d
		
}

start() {
	config_load airplay
	config_foreach handle_airplay airplay
}

stop() {
	killall -9 shairport
	killall -9 avahi-publish-service
}


